import {SysMenu} from "./types.ts";
import {request} from "@/api";

const apiPrefix = '/varian-system/menu'

export const menuApi = {
    add: (data: SysMenu) => request.post(`${apiPrefix}`, {data}),
    tree: (params: any) => request.get<SysMenu[]>(`${apiPrefix}/tree`, {params}),
    detail: (id: string) => request.get<SysMenu>(`${apiPrefix}/${id}`),
    delete: (id: string) => request.delete(`${apiPrefix}/${id}`),
    modify: (data: SysMenu) => request.put(`${apiPrefix}/${data.id}`, {data}),
    treeByUser: () => request.get<SysMenu[]>(`${apiPrefix}/tree-by-user`),
    list: (params: { parentId: string }) => request.get<SysMenu[]>(`${apiPrefix}/list`, {params}),
    updateWeights: (parentId: string, data: {
        id: string,
        menuWeight: number
    }[]) => request.put(`${apiPrefix}/weights/${parentId}`, {data}),
}
